// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
//    conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
//    of conditions and the following disclaimer in the documentation and/or other
//    materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
//    used to endorse or promote products derived from this software without specific
//    prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers

#pragma once

#include <array>
#include <stdexcept>
#include <string>
#include <boost/uuid/uuid.hpp>
#include <stdexcept>
#include <chrono>

#define CRYPTONOTE_DNS_TIMEOUT_MS 20000

#define CRYPTONOTE_MAX_BLOCK_NUMBER 500000000
#define CRYPTONOTE_MAX_TX_SIZE 1000000
#define CRYPTONOTE_MAX_TX_PER_BLOCK 0x10000000
#define CRYPTONOTE_PUBLIC_ADDRESS_TEXTBLOB_VER 0
#define CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW 60
#define CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V2 60 * 10
#define CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE 10
#define CRYPTONOTE_DEFAULT_TX_MIXIN 9

#define STAKING_REQUIREMENT_LOCK_BLOCKS_EXCESS 20
#define STAKING_PORTIONS UINT64_C(0xfffffffffffffffc)
#define MAX_NUMBER_OF_CONTRIBUTORS 4
#define MIN_PORTIONS (STAKING_PORTIONS / MAX_NUMBER_OF_CONTRIBUTORS)

static_assert(STAKING_PORTIONS % 12 == 0, "Use a multiple of twelve, so that it divides evenly by two, three, or four contributors.");

#define STAKING_AUTHORIZATION_EXPIRATION_WINDOW (60 * 60 * 24 * 7 * 2) // 2 weeks

#define BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW 11

// For local testnet debug purposes allow shrinking the uptime proof frequency
#ifndef UPTIME_PROOF_BASE_MINUTE
#define UPTIME_PROOF_BASE_MINUTE 60
#endif

#define UPTIME_PROOF_BUFFER_IN_SECONDS (5 * 60)                                                                   // The acceptable window of time to accept a peer's uptime proof from its reported timestamp
#define UPTIME_PROOF_INITIAL_DELAY_SECONDS (2 * UPTIME_PROOF_BASE_MINUTE)                                         // Delay after startup before sending a proof (to allow connections to be established)
#define UPTIME_PROOF_TIMER_SECONDS (5 * UPTIME_PROOF_BASE_MINUTE)                                                 // How often we check whether we need to send an uptime proof
#define UPTIME_PROOF_FREQUENCY_IN_SECONDS (60 * UPTIME_PROOF_BASE_MINUTE)                                         // How often we resend uptime proofs normally (i.e. after we've seen an uptime proof reply from the network)
#define UPTIME_PROOF_MAX_TIME_IN_SECONDS (UPTIME_PROOF_FREQUENCY_IN_SECONDS * 2 + UPTIME_PROOF_BUFFER_IN_SECONDS) // How long until proofs of other network service nodes are considered expired

#define STORAGE_SERVER_PING_LIFETIME UPTIME_PROOF_FREQUENCY_IN_SECONDS
#define SISPOPNET_PING_LIFETIME UPTIME_PROOF_FREQUENCY_IN_SECONDS

#define CRYPTONOTE_REWARD_BLOCKS_WINDOW 100
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 20000   // NOTE(sispop): For testing suite, //size of block (bytes) after which reward for block calculated using block size - before first fork
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 300000  // size of block (bytes) after which reward for block calculated using block size - second change, from v5
#define CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE 100000 // size in blocks of the long term block weight median window
#define CRYPTONOTE_SHORT_TERM_BLOCK_WEIGHT_SURGE_FACTOR 50
#define CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE 600
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 9

#define FEE_PER_KB ((uint64_t)2000000000)                               // 2 SISPOP (= 2 * pow(10, 9))
#define FEE_PER_BYTE ((uint64_t)215)                                    // Fallback used in wallet if no fee is available from RPC
#define FEE_PER_BYTE_V12 ((uint64_t)17200)                              // Higher fee (and fallback) in v12 (only, v13 switches back)
#define FEE_PER_OUTPUT ((uint64_t)20000000)                             // 0.02 SISPOP per tx output (in addition to the per-byte fee), starting in v13
#define DYNAMIC_FEE_PER_KB_BASE_BLOCK_REWARD ((uint64_t)10000000000000) // 10 * pow(10,12)
#define DYNAMIC_FEE_PER_KB_BASE_FEE_V5 ((uint64_t)400000000)
#define DYNAMIC_FEE_REFERENCE_TRANSACTION_WEIGHT ((uint64_t)3000)
#define DYNAMIC_FEE_REFERENCE_TRANSACTION_WEIGHT_V12 ((uint64_t)240000) // Only v12 (v13 switches back)

#define DIFFICULTY_TARGET_V2 120 // seconds
#define DIFFICULTY_WINDOW_V2 60
#define DIFFICULTY_BLOCKS_COUNT_V2 (DIFFICULTY_WINDOW_V2 + 1) // added +1 to make N=N
#define TARGET_BLOCK_TIME 5 * 60

#define BLOCKS_EXPECTED_IN_HOURS(val) (((60 * 60) / DIFFICULTY_TARGET_V2) * (val))
#define BLOCKS_EXPECTED_IN_DAYS(val) (BLOCKS_EXPECTED_IN_HOURS(24) * (val))
#define BLOCKS_EXPECTED_IN_YEARS(val) (BLOCKS_EXPECTED_IN_DAYS(365) * (val))

#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 DIFFICULTY_TARGET_V2 *CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS
#define CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS 1

#define BLOCKS_IDS_SYNCHRONIZING_DEFAULT_COUNT 10000 // by default, blocks ids count in synchronizing
#define BLOCKS_SYNCHRONIZING_DEFAULT_COUNT 100       // by default, blocks count in blocks downloading
#define BLOCKS_SYNCHRONIZING_MAX_COUNT 2048          // must be a power of 2, greater than 128, equal to SEEDHASH_EPOCH_BLOCKS

#define CRYPTONOTE_MEMPOOL_TX_LIVETIME (86400 * 3)                // seconds, three days
#define CRYPTONOTE_MEMPOOL_TX_FROM_ALT_BLOCK_LIVETIME (86400 * 7) // seconds, one week

#define MEMPOOL_PRUNE_NON_STANDARD_TX_LIFETIME (2 * 60 * 60) // seconds, 2 hours

#define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT 1000
#define COMMAND_RPC_GET_CHECKPOINTS_MAX_COUNT 256
#define COMMAND_RPC_GET_QUORUM_STATE_MAX_COUNT 256
#define MAX_RPC_CONTENT_LENGTH 1048576 // 1 MB

#define P2P_LOCAL_WHITE_PEERLIST_LIMIT 1000
#define P2P_LOCAL_GRAY_PEERLIST_LIMIT 5000

#define P2P_DEFAULT_CONNECTIONS_COUNT_OUT 8
#define P2P_DEFAULT_CONNECTIONS_COUNT_IN 32
#define P2P_DEFAULT_HANDSHAKE_INTERVAL 60    // secondes
#define P2P_DEFAULT_PACKET_MAX_SIZE 50000000 // 50000000 bytes maximum packet size
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE 250
#define P2P_DEFAULT_CONNECTION_TIMEOUT 5000       // 5 seconds
#define P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT 45      // seconds
#define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000  // 2 seconds
#define P2P_DEFAULT_INVOKE_TIMEOUT 60 * 2 * 1000  // 2 minutes
#define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 // 5 seconds
#define P2P_DEFAULT_WHITELIST_CONNECTIONS_PERCENT 70
#define P2P_DEFAULT_ANCHOR_CONNECTIONS_COUNT 2
#define P2P_DEFAULT_SYNC_SEARCH_CONNECTIONS_COUNT 2
#define P2P_DEFAULT_LIMIT_RATE_UP 2048   // kB/s
#define P2P_DEFAULT_LIMIT_RATE_DOWN 8192 // kB/s

#define P2P_FAILED_ADDR_FORGET_SECONDS (60 * 60) // 1 hour
#define P2P_IP_BLOCKTIME (60 * 60 * 24)          // 24 hour
#define P2P_IP_FAILS_BEFORE_BLOCK 10
#define P2P_IDLE_CONNECTION_KILL_INTERVAL (5 * 60) // 5 minutes

// TODO(doyle): Deprecate after checkpointing hardfork, remove notion of being
// able to sync non-fluffy blocks, keep here so we can still accept blocks
// pre-hardfork
#define P2P_SUPPORT_FLAG_FLUFFY_BLOCKS 0x01
#define P2P_SUPPORT_FLAGS P2P_SUPPORT_FLAG_FLUFFY_BLOCKS

#define CRYPTONOTE_NAME "sispop"
#define CRYPTONOTE_POOLDATA_FILENAME "poolstate.bin"
#define CRYPTONOTE_BLOCKCHAINDATA_FILENAME "data.mdb"
#define CRYPTONOTE_BLOCKCHAINDATA_LOCK_FILENAME "lock.mdb"
#define P2P_NET_DATA_FILENAME "p2pstate.bin"
#define MINER_CONFIG_FILE_NAME "miner_conf.json"

#define THREAD_STACK_SIZE 5 * 1024 * 1024

#define HF_VERSION_PER_BYTE_FEE cryptonote::network_version_10_bulletproofs
#define HF_VERSION_SMALLER_BP cryptonote::network_version_11_infinite_staking
#define HF_VERSION_LONG_TERM_BLOCK_WEIGHT cryptonote::network_version_11_infinite_staking
#define HF_VERSION_INCREASE_FEE cryptonote::network_version_12_checkpointing
#define HF_VERSION_PER_OUTPUT_FEE cryptonote::network_version_13_enforce_checkpoints
#define HF_VERSION_ED25519_KEY cryptonote::network_version_13_enforce_checkpoints
#define HF_VERSION_FEE_BURNING cryptonote::network_version_14_blink
#define HF_VERSION_BLINK cryptonote::network_version_14_blink

#define HF_VERSION_DJED 3

#define PER_KB_FEE_QUANTIZATION_DECIMALS 8

#define HASH_OF_HASHES_STEP 256

#define DEFAULT_TXPOOL_MAX_WEIGHT 648000000ull // 3 days at 300000, in bytes

#define BULLETPROOF_MAX_OUTPUTS 16
#define BULLETPROOF_PLUS_MAX_OUTPUTS 16

#define CRYPTONOTE_PRUNING_STRIPE_SIZE 4096 // the smaller, the smoother the increase
#define CRYPTONOTE_PRUNING_LOG_STRIPES 3    // the higher, the more space saved
#define CRYPTONOTE_PRUNING_TIP_BLOCKS 5500  // the smaller, the more space saved
// #define CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED

// The limit is enough for the mandatory transaction content with 16 outputs (547 bytes),
// a custom tag (1 byte) and up to 32 bytes of custom data for each recipient.
//  (1+32) + (1+1+16*32) + (1+16*32) = 1060
#define MAX_TX_EXTRA_SIZE 1060

// New constants are intended to go here
namespace config
{
  uint64_t const DEFAULT_FEE_ATOMIC_XMR_PER_KB = 500; // Just a placeholder!  Change me!
  uint8_t const FEE_CALCULATION_MAX_RETRIES = 10;
  uint64_t const DEFAULT_DUST_THRESHOLD = ((uint64_t)2000000000);     // 2 * pow(10, 9)
  uint64_t const BASE_REWARD_CLAMP_THRESHOLD = ((uint64_t)100000000); // pow(10, 8)
  std::string const P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY = "0000000000000000000000000000000000000000000000000000000000000000";

  uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18;
  uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = 19;
  uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = 20;
  uint16_t const P2P_DEFAULT_PORT = 20000;
  uint16_t const RPC_DEFAULT_PORT = 30000;
  uint16_t const ZMQ_RPC_DEFAULT_PORT = 40000;
  uint16_t const QNET_DEFAULT_PORT = 50000;
  boost::uuids::uuid const NETWORK_ID = {{0x01, 0x30, 0x60, 0x70, 0x15, 0x30, 0x45, 0x60, 0x75, 0x80, 0x34, 0x67, 0x25, 0x39, 0x80}}; // Bender's nightmare
  std::string const GENESIS_TX = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1";
  uint32_t const GENESIS_NONCE = 70;

  // Hash domain separators
  const char HASH_KEY_BULLETPROOF_EXPONENT[] = "bulletproof";
  const char HASH_KEY_RINGDB[] = "ringdsb";
  const char HASH_KEY_SUBADDRESS[] = "SubAddr";
  const unsigned char HASH_KEY_ENCRYPTED_PAYMENT_ID = 0x8d;
  const unsigned char HASH_KEY_WALLET = 0x8c;
  const unsigned char HASH_KEY_WALLET_CACHE = 0x8d;
  const unsigned char HASH_KEY_RPC_PAYMENT_NONCE = 0x58;
  const unsigned char HASH_KEY_MEMORY = 'k';
  const unsigned char HASH_KEY_MULTISIG[] = {'M', 'u', 'l', 't', 'i', 's', 'i', 'g', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  const unsigned char HASH_KEY_TXPROOF_V2[] = "TXPROOF_V2";

  uint64_t const GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS = ((60 * 60 * 24 * 7) / DIFFICULTY_TARGET_V2);
  const unsigned char HASH_KEY_MULTISIG_KEY_AGGREGATION[] = "Multisig_key_agg";
  const unsigned char HASH_KEY_CLSAG_ROUND_MULTISIG[] = "CLSAG_round_ms_merge_factor";
  const unsigned char HASH_KEY_CLSAG_ROUND[] = "CLSAG_round";
  const unsigned char HASH_KEY_CLSAG_AGG_0[] = "CLSAG_agg_0";
  const unsigned char HASH_KEY_CLSAG_AGG_1[] = "CLSAG_agg_1";
  const char HASH_KEY_MESSAGE_SIGNING[] = "SispopMessageSignature";
  const unsigned char HASH_KEY_MM_SLOT = 'm';
  const constexpr char HASH_KEY_MULTISIG_TX_PRIVKEYS_SEED[] = "multisig_tx_privkeys_seed";
  const constexpr char HASH_KEY_MULTISIG_TX_PRIVKEYS[] = "multisig_tx_privkeys";
  const constexpr char HASH_KEY_TXHASH_AND_MIXRING[] = "txhash_and_mixring";

  // Multisig
  const uint32_t MULTISIG_MAX_SIGNERS{16};

  std::string const GOVERNANCE_WALLET_ADDRESS[] =
      {
          "49HsfhWTvKZgc4qH1hwcEpM99Ng2TqmcxVHJoSkSQvV3N9iVJP1NT6gJTWRvuTWMNqeDgHNUcrpYVdnXW5Ep33W33YfwqRe",
          "49HsfhWTvKZgc4qH1hwcEpM99Ng2TqmcxVHJoSkSQvV3N9iVJP1NT6gJTWRvuTWMNqeDgHNUcrpYVdnXW5Ep33W33YfwqRe",
  };

  namespace testnet
  {
    uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 156;
    uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = 157;
    uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = 158;
    uint16_t const P2P_DEFAULT_PORT = 38156;
    uint16_t const RPC_DEFAULT_PORT = 38157;
    uint16_t const ZMQ_RPC_DEFAULT_PORT = 38158;
    uint16_t const QNET_DEFAULT_PORT = 38159;
    boost::uuids::uuid const NETWORK_ID = {{
        0x22,
        0x3a,
        0x78,
        0x65,
        0x88,
        0x6f,
        0xca,
        0xb8,
        0x01,
        0xa1,
        0xdc,
        0x07,
        0x71,
        0x55,
        0x15,
        0x22,
    }}; // Bender's daydream
    std::string const GENESIS_TX = "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017767aafcde9be00dcfd098715ebcf7f410daebc582fda69d24a28e9d0bc890d1";
    uint32_t const GENESIS_NONCE = 10001;

    uint64_t const GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS = 1000;
    std::string const GOVERNANCE_WALLET_ADDRESS[] =
        {
            "T6TU9yWHiYwKnJLWKoBQyWKXQSkRv7WnPacqFzrw5kPvgJJM7oQn4GNCPDimwU87RxVy69cRgpMoFUeZpTqyjGR91nW2PYdkq", // hardfork v7-9
            "T6TU9yWHiYwKnJLWKoBQyWKXQSkRv7WnPacqFzrw5kPvgJJM7oQn4GNCPDimwU87RxVy69cRgpMoFUeZpTqyjGR91nW2PYdkq", // hardfork v10
    };

    std::array<std::string, 1> const ORACLE_URLS = {{"https://sispop-dev-oracle.onrender.com/"}};

    std::string const ORACLE_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n"
                                          "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA02Gh3CcFQ0rJGUe13rbd\n"
                                          "FOhRN2Sf6h6TUGhdVtVl991Jb+cD56uyvb6Pay/OI/PI6KFj7nuAZyRw1rrP5o+p\n"
                                          "Uel6/CX0d3reLU+xCiQLz3CsaGYOT2piqoQZlTIJKMFNfO1WY6+azXyUmwTZ7kVw\n"
                                          "C2bVgmgk+JWuILMqL2agwGP4r+05jPLil5kftQbZn0QaSny05ihjnrwv9dyKQJEY\n"
                                          "zTg8/lljwbrH3TpVU+kEqaMyglDA3MB1/6K4xQ0Vr3lJTdmy9FQxUGm/ad4pzl7o\n"
                                          "GM1Mxn8isMBWtfB5BcApOFpYlufXuMlv5X3zK6LQ4zG9ZWCG/wOqy1RH3S5WiZuo\n"
                                          "XwIDAQAB\n"
                                          "-----END PUBLIC KEY-----\n";
  }

  namespace stagenet
  {
    uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 24;
    uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = 25;
    uint64_t const CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX = 36;
    uint16_t const P2P_DEFAULT_PORT = 38056;
    uint16_t const RPC_DEFAULT_PORT = 38057;
    uint16_t const ZMQ_RPC_DEFAULT_PORT = 38058;
    uint16_t const QNET_DEFAULT_PORT = 38059;
    boost::uuids::uuid const NETWORK_ID = {{0xbb, 0x37, 0x55, 0x22, 0x0A, 0x66, 0x19, 0x65, 0x09, 0xB2, 0x97, 0x8A, 0xCC, 0x01, 0xDF, 0x9C}}; // Beep Boop
    std::string const GENESIS_TX = "013c01ff0001ffffffffffff0302df5d56da0c7d643ddd1ce61901c7bdc5fb1738bfe39fbe69c28a3a7032729c0f2101168d0c4ca86fb55a4cf6a36d31431be1c53a3bd7411bb24e8832410289fa6f3b";
    uint32_t const GENESIS_NONCE = 10002;

    uint64_t const GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS = ((60 * 60 * 24 * 7) / DIFFICULTY_TARGET_V2);
    std::string const GOVERNANCE_WALLET_ADDRESS[] =
        {
            "5A8U5rKBGTQNN3JoNDFPyTgARrmvqyMgR15ZGSFWhRgJ9JA62V6gUox8NbVCq9Y2jCVcuWPETLAzoNSWvCyYBxGtRPG4TVq", // hardfork v7-9
            "5A8U5rKBGTQNN3JoNDFPyTgARrmvqyMgR15ZGSFWhRgJ9JA62V6gUox8NbVCq9Y2jCVcuWPETLAzoNSWvCyYBxGtRPG4TVq", // hardfork v10
    };

    std::array<std::string, 1> const ORACLE_URLS = {{"https://sispop-dev-oracle.onrender.com/"}};

    std::string const ORACLE_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n"
                                          "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA02Gh3CcFQ0rJGUe13rbd\n"
                                          "FOhRN2Sf6h6TUGhdVtVl991Jb+cD56uyvb6Pay/OI/PI6KFj7nuAZyRw1rrP5o+p\n"
                                          "Uel6/CX0d3reLU+xCiQLz3CsaGYOT2piqoQZlTIJKMFNfO1WY6+azXyUmwTZ7kVw\n"
                                          "C2bVgmgk+JWuILMqL2agwGP4r+05jPLil5kftQbZn0QaSny05ihjnrwv9dyKQJEY\n"
                                          "zTg8/lljwbrH3TpVU+kEqaMyglDA3MB1/6K4xQ0Vr3lJTdmy9FQxUGm/ad4pzl7o\n"
                                          "GM1Mxn8isMBWtfB5BcApOFpYlufXuMlv5X3zK6LQ4zG9ZWCG/wOqy1RH3S5WiZuo\n"
                                          "XwIDAQAB\n"
                                          "-----END PUBLIC KEY-----\n";
  }
}

namespace cryptonote
{
  enum network_version
  {
    network_version_7 = 7,
    network_version_8,
    network_version_9_service_nodes,     // Proof Of Stake w/ Service Nodes
    network_version_10_bulletproofs,     // Bulletproofs, Service Node Grace Registration Period, Batched Governance
    network_version_11_infinite_staking, // Infinite Staking, CN-Turtle
    network_version_12_checkpointing,    // Checkpointing, Relaxed Deregistration, RandomXL, Sispop Storage Server
    network_version_13_enforce_checkpoints,
    network_version_14_blink,
    network_version_15_lns,
    network_version_16, // future fork
    network_version_17,
    network_version_18,

    network_version_count,
  };

  enum network_type : uint8_t
  {
    MAINNET = 0,
    TESTNET,
    STAGENET,
    FAKECHAIN,
    UNDEFINED = 255
  };
  struct config_t
  {
    uint64_t CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX;
    uint64_t CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX;
    uint64_t CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX;
    uint16_t P2P_DEFAULT_PORT;
    uint16_t RPC_DEFAULT_PORT;
    uint16_t ZMQ_RPC_DEFAULT_PORT;
    uint16_t QNET_DEFAULT_PORT;
    boost::uuids::uuid NETWORK_ID;
    std::string GENESIS_TX;
    uint32_t GENESIS_NONCE;
    uint64_t GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS;
    std::string const *GOVERNANCE_WALLET_ADDRESS;
    std::array<std::string, 1> const ORACLE_URLS;
    std::string const ORACLE_PUBLIC_KEY;
  };
  inline const config_t &get_config(network_type nettype, int hard_fork_version = 7)
  {
    static config_t mainnet = {
        ::config::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX,
        ::config::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX,
        ::config::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX,
        ::config::P2P_DEFAULT_PORT,
        ::config::RPC_DEFAULT_PORT,
        ::config::ZMQ_RPC_DEFAULT_PORT,
        ::config::QNET_DEFAULT_PORT,
        ::config::NETWORK_ID,
        ::config::GENESIS_TX,
        ::config::GENESIS_NONCE,
        ::config::GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS,
        &::config::GOVERNANCE_WALLET_ADDRESS[0],
    };

    static config_t testnet = {
        ::config::testnet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX,
        ::config::testnet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX,
        ::config::testnet::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX,
        ::config::testnet::P2P_DEFAULT_PORT,
        ::config::testnet::RPC_DEFAULT_PORT,
        ::config::testnet::ZMQ_RPC_DEFAULT_PORT,
        ::config::testnet::QNET_DEFAULT_PORT,
        ::config::testnet::NETWORK_ID,
        ::config::testnet::GENESIS_TX,
        ::config::testnet::GENESIS_NONCE,
        ::config::testnet::GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS,
        &::config::testnet::GOVERNANCE_WALLET_ADDRESS[0],
        ::config::testnet::ORACLE_URLS,
        ::config::testnet::ORACLE_PUBLIC_KEY};

    static config_t stagenet = {
        ::config::stagenet::CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX,
        ::config::stagenet::CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX,
        ::config::stagenet::CRYPTONOTE_PUBLIC_SUBADDRESS_BASE58_PREFIX,
        ::config::stagenet::P2P_DEFAULT_PORT,
        ::config::stagenet::RPC_DEFAULT_PORT,
        ::config::stagenet::ZMQ_RPC_DEFAULT_PORT,
        ::config::stagenet::QNET_DEFAULT_PORT,
        ::config::stagenet::NETWORK_ID,
        ::config::stagenet::GENESIS_TX,
        ::config::stagenet::GENESIS_NONCE,
        ::config::stagenet::GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS,
        &::config::stagenet::GOVERNANCE_WALLET_ADDRESS[0],
        ::config::stagenet::ORACLE_URLS,
        ::config::stagenet::ORACLE_PUBLIC_KEY};

    switch (nettype)
    {
    case MAINNET:
    case FAKECHAIN:
    {
      if (nettype == FAKECHAIN)
        mainnet.GOVERNANCE_REWARD_INTERVAL_IN_BLOCKS = 100;

      if (hard_fork_version <= network_version_10_bulletproofs)
        mainnet.GOVERNANCE_WALLET_ADDRESS = &::config::GOVERNANCE_WALLET_ADDRESS[0];
      else
        mainnet.GOVERNANCE_WALLET_ADDRESS = &::config::GOVERNANCE_WALLET_ADDRESS[1];

      return mainnet;
    }

    case TESTNET:
    {
      if (hard_fork_version <= network_version_9_service_nodes)
        testnet.GOVERNANCE_WALLET_ADDRESS = &::config::testnet::GOVERNANCE_WALLET_ADDRESS[0];
      else
        testnet.GOVERNANCE_WALLET_ADDRESS = &::config::testnet::GOVERNANCE_WALLET_ADDRESS[1];

      return testnet;
    }

    case STAGENET:
    {
      if (hard_fork_version <= network_version_9_service_nodes)
        stagenet.GOVERNANCE_WALLET_ADDRESS = &::config::stagenet::GOVERNANCE_WALLET_ADDRESS[0];
      else
        stagenet.GOVERNANCE_WALLET_ADDRESS = &::config::stagenet::GOVERNANCE_WALLET_ADDRESS[1];

      return stagenet;
    }

    default:
      throw std::runtime_error("Invalid network type");
    }
  };
}
